<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>组件添加v-model</h3>
      <p>{{ msg }}</p>
      <!-- <child :value="msg" @input="getvalue"></child> -->
      <child v-model="msg"></child>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      // 父组件的变量和子组件的input的内容做双向绑定

      Vue.component("child", {
        props: ["value"],
        template: `
          <input type="text" :value="value" @input="handleInput" />
        `,
        methods: {
          handleInput(e) {
            // console.log(e.target.value);
            this.$emit("input", e.target.value);
          },
        },
      });

      const vm = new Vue({
        el: "#app",
        data: {
          msg: "hello",
        },
        // methods: {
        //   getvalue(v) {
        //     this.msg = v;
        //   },
        // },
      });
    </script>
  </body>
</html>
